﻿using Cxuu.Common;
using Cxuu.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Threading.Tasks;

namespace Cxuu.Web.Admin
{
    [Area("Admin")]
    [Authorize]
    public class CacheController : Base
    {
        private readonly ICacheManager _cacheManager;
        private readonly LogService _logService;
        public CacheController(ICacheManager cacheManager, LogService logService)
        {
            _cacheManager = cacheManager;
            _logService = logService;
        }

        [HttpGet]
        public IActionResult Index(int json = 0)
        {
            if (json == 1)
            {
                string name = Appsettings.App(new string[] { "CacheService", "CacheEngine" });
                List<ViewCacheModel> cacheList;
                if (name == "Redis")
                {
                    cacheList = new()
                    {
                        new ViewCacheModel() { Name = "Redis(启用)", Val = _cacheManager.TotalNumber(), Size = 0 },
                        new ViewCacheModel() { Name = "Memory", Val = 0, Size = 0 },
                    };
                }
                else
                {
                    cacheList = new()
                    {
                        new ViewCacheModel() { Name = "Redis", Val = 0, Size = 0 },
                        new ViewCacheModel() { Name = "Memory(启用)", Val = _cacheManager.TotalNumber(), Size = 0 },
                    };
                }

                return Json(new { code = 0, data = cacheList });
            }
            return View();


        }


    }
}
